# coding=utf-8
from django import template
from StudyPlatform.models import Courses, CourseVideos
from django.contrib.auth.models import User

register = template.Library()


# 获取课程的url
@register.filter(name='getCourseUrl')
def getCourseUrl(val):
    return Courses.objects.filter(id=val)[0].courseurl


# 获取课程的图片地址
@register.filter(name='getCourseImgUrl')
def getCourseImgUrl(val):
    return Courses.objects.filter(id=val)[0].imgurl


# 获取课程的视频名称
@register.filter(name='getCourseVideoName')
def getCourseVideoName(val):
    return Courses.objects.filter(id=val)[0].videoname


# 获取课程的名称
@register.filter(name='getCourseName')
def getCourseName(val):
    return Courses.objects.filter(id=val)[0].coursename


# 通过课程id获取第一个课程视频id
@register.filter(name='getCourseVideoId')
def getCourseVideoId(val):
    return CourseVideos.objects.filter(courses_id=val)[0].id


# 获取课程视频的播放地址
@register.filter(name='getCourseVideoUrl')
def getCourseVideoUrl(val):
    return CourseVideos.objects.filter(id=val)[0].videourl


# 获取用户昵称
@register.filter(name='getFirstName')
def getFirstName(val):
    return User.objects.filter(id=val)[0].first_name
